//
//  FlashIndicatorButton.m
//  iShow
//
//  Created by 杨 敏 on 12-11-28.
//  Copyright (c) 2012年 DreamTeam. All rights reserved.
//

#import "FlashIndicatorButton.h"

@implementation FlashIndicatorButton

-(void)dealloc{
    self.indicator=nil;
}
- (void)willMoveToSuperview:(UIView *)newSuperview {
	[super willMoveToSuperview:newSuperview];
	if(!newSuperview) {
        // DLog(@"");
        [self cancelCurrentImageLoad];
	}
}
+ (FlashIndicatorButton *)buttonWithType:(UIButtonType)buttonType{
    FlashIndicatorButton *btn =(FlashIndicatorButton *)[super buttonWithType:buttonType];
    return btn;
}

-(void)startIndicatorAnimating{
   // DLog(@"");
    if (!_indicator) {
        self.indicator =[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:_isWhiteIndicator?UIActivityIndicatorViewStyleWhite:UIActivityIndicatorViewStyleGray];
        [self addSubview:_indicator];
    }
    _indicator.center=CGPointMake(CGRectGetWidth(self.frame)/2, CGRectGetHeight(self.frame)/2);

    [_indicator startAnimating];
}
-(void)endIndicatorAnimating{
  //  DLog(@"");
    
    [_indicator stopAnimating];
    [_indicator removeFromSuperview];
    self.indicator=nil;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    _indicator.center=CGPointMake(CGRectGetWidth(self.frame)/2, CGRectGetHeight(self.frame)/2);
}
@end
